﻿using System;

namespace NeroConnect.Network
{
	/// <summary>Standard implementation of IFactory.</summary>
	public class Factory : IFactory
	{
		/// <summary>Constructor for the factory</summary>
		public Factory()
		{
			System.Net.ServicePointManager.DefaultConnectionLimit = 64;
		}

		/// <see cref="IFactory"/>
		public IRequest CreateRequest(string requestUriString)
		{
			return CreateRequest(new Uri(requestUriString));
		}

		/// <see cref="IFactory"/>
		public IRequest CreateRequest(Uri requestUri)
		{
			return new HttpRequest(requestUri);
		}

		/// <see cref="IFactory"/>
        public MiniHttpServer.IHttpListener CreateListener(int port)
		{
			return MiniHttpServer.IHttpListener.Create(System.Net.IPAddress.Any, port);
		}

		/// <see cref="IFactory"/>
		public IUdpClient CreateUdpClient(System.Net.IPEndPoint endPoint)
		{
			return new UdpClient(endPoint);
		}

		/// <see cref="IFactory"/>
		public IUdpClient CreateUdpClient(int port, System.Net.Sockets.AddressFamily addressFamily)
		{
			return new UdpClient(port, addressFamily);
		}

		/// <see cref="IFactory"/>
		public IUdpClient CreateUdpClient(int port)
		{
			return new UdpClient(port);
		}
	}
}
